<%@ page language="java" import="java.util.*,java.sql.*"
	pageEncoding="UTF-8"%>
<html>
<head>
<title>回收站还原信息</title>
</head>

<body>
	<%
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url1 = "jdbc:mysql://localhost:3306/user";
			String url2 = "?user=root&password=123456";
			String url3 = "&useUnicode=true&characterEncoding=UTF-8";
			String url = url1 + url2 + url3;
			Connection con = DriverManager.getConnection(url);
			request.setCharacterEncoding("UTF-8");
			String user = (String) session.getAttribute("user");
			String name = request.getParameter("name");
			String sql = "select * from recycle where name=? and user=" + "'"
					+ user + "'";
			PreparedStatement pstmt = con.prepareStatement(sql);
			pstmt.setString(1, name);
			ResultSet rs = pstmt.executeQuery();
			String sql1 = "insert into person(id, name, num, user) values(?, ?, ?, ?)";
			PreparedStatement pstmt2 = con.prepareStatement(sql1);
			while (rs.next()) {
				pstmt2.setInt(1, rs.getInt("id"));
				pstmt2.setString(2, rs.getString("name"));
				pstmt2.setString(3, rs.getString("num"));
				pstmt2.setString(4, rs.getString("user"));
			}
			int n = pstmt2.executeUpdate();
			if (n >= 1)
				out.print("还原成功!");
			else
				out.print("还原失败!");
			if (rs != null)
				rs.close();
			if (pstmt2 != null)
				pstmt2.close();
			sql = "delete from recycle where name=?";
			pstmt = con.prepareStatement(sql);
			pstmt.setString(1, name);
			n = pstmt.executeUpdate();
			if (pstmt != null)
				pstmt.close();
			if (con != null)
				con.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	%>
	<form action="recycle_restore.jsp" method="post">
		<h3 style="text-align: center;">还原信息</h3>
		<table style="margin: auto;">
			<tr>
				<td>name</td>
				<td><input type="text" name="name"></td>
			</tr>
			<tr>
				<td><input type="submit" value="提交">
				</td>
				<td><input type="reset" value="取消">
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
